﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.data.GameData;
	import com.wandian.util.ButtonUtil;
	import com.wandian.util.CLZButton;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

    public class AddBtn extends Object
    {
        private static var _facade:ApplicationFacade = ApplicationFacade.getInstance();
        public static const CLOSE:int = 1;
        public static const OK:int = 2;
        public static const CANCEL:int = 3;
        public static const OTHER:int = 4;
        public static const CLOSE_TWO:int = 5;
        public static const CLOSE_THREE:int = 6;

        public function AddBtn()
        {
            return;
        }

        public static function initBtn(parentMc:Sprite, strNotice:String, type:int = 1, txtName:String = "", numX:Number = 6, numY:Number = 6, objData:Object = null, className:String = "Otherbtn") : void
        {
            var btn:DisplayObject;
            var onHandler:Function;     
            onHandler = function (event:MouseEvent) : void
            {
                _facade.sendNotification(strNotice, objData);
                return;
            }
            ;
            switch(type)
            {
                case CLOSE:
                {
                    btn = GameData.getButton("CloseBtn");
                    btn.x = parentMc.width - numX - btn.width;
                    btn.y = numY;
                    break;
                }
                case CLOSE_TWO:
                {
                    btn = GameData.getButton("CloseBtn2");
                    btn.x = parentMc.width - btn.width - numX;
                    btn.y = numY;
                    break;
                }
                case CLOSE_THREE:
                {
                    btn = GameData.getButton("CloseBtn3");
                    btn.x = numX;
                    btn.y = numY;
                    break;
                }
                case OK:
                {
                    btn = GameData.getMovieClip("OKBtn");
					ButtonUtil.setButton(btn as MovieClip, txtName);
                    btn.x = numX;
                    btn.y = numY;
                    break;
                }
                case CANCEL:
                {
                    btn = GameData.getMovieClip("CancelBtn");
                    ButtonUtil.setButton(btn as MovieClip, txtName);
                    btn.x = numX;
                    btn.y = numY;
                    break;
                }
                case OTHER:
                {
                    btn = GameData.getMovieClip(className);
                    ButtonUtil.setButton(btn as MovieClip, txtName);
                    btn.x = numX;
                    btn.y = numY;
                    break;
                }
                default:
                {
                    break;
                }
            }
            parentMc.addChild(btn);
            btn.addEventListener(MouseEvent.CLICK, onHandler);
            return;
        }
		public static function initFunBtn(parentMc:Sprite, fun:Function, type:int = 1, txtName:String = "", numX:Number = 6, numY:Number = 6, objData:Object = null, className:String = "Otherbtn") : DisplayObject
		{
			var btn:DisplayObject;			
			switch(type)
			{
				case CLOSE:
				{
					btn = GameData.getButton("CloseBtn");
					btn.x = parentMc.width - numX - btn.width;
					btn.y = numY;
					break;
				}
				case CLOSE_TWO:
				{
					btn = GameData.getButton("CloseBtn2");
					btn.x = parentMc.width - btn.width - numX;
					btn.y = numY;
					break;
				}
				case CLOSE_THREE:
				{
					btn = GameData.getButton("CloseBtn3");
					btn.x = numX;
					btn.y = numY;
					break;
				}
				case OK:
				{
					btn = GameData.getMovieClip("OKBtn");
					CLZButton.setButton(btn as MovieClip, txtName);
					btn.x = numX;
					btn.y = numY;
					break;
				}
				case CANCEL:
				{
					btn = GameData.getMovieClip("CancelBtn");
					CLZButton.setButton(btn as MovieClip, txtName);
					btn.x = numX;
					btn.y = numY;
					break;
				}
				case OTHER:
				{
					btn = GameData.getMovieClip(className);
					CLZButton.setButton(btn as MovieClip, txtName);
					btn.x = numX;
					btn.y = numY;
					break;
				}
				default:
				{
					break;
				}
			}
			parentMc.addChild(btn);
			btn.name="btn";
			btn.addEventListener(MouseEvent.CLICK, fun);
			return btn;
		}
        public static function addCurrentFunBtn(parentMc:Sprite, fun:Function, txtName:String = "", numX:Number = 6, numY:Number = 6, className:String = "Otherbtn", obj:Object = null) : void
        {
            var btn:DisplayObject;
			var onHandler:Function;           
			onHandler = function (event:MouseEvent) : void
			{
				if (obj == null)
				{
					fun();
				}
				else
				{
					fun(obj);
				}
				return;
			}
            ;
            trace("txtName:" + txtName, className);
			if(txtName==null){
				switch(className)
				{
					case "OKBtn":
					{
						txtName=GameData.tip["OK"];
						break;
					}
					case "OKBtn":
					{
						txtName=GameData.tip["OK"];
						break;
					}	
					default:
					{
						break;
					}
				}
			}
            if (className == "CloseBtn2")
            {
                btn = GameData.getButton(className);
            }
            else
            {
                btn = GameData.getMovieClip(className);
                ButtonUtil.setButton(btn as MovieClip, txtName);
            }
            btn.x = numX;
            btn.y = numY;
            parentMc.addChild(btn);
            btn.addEventListener(MouseEvent.CLICK, onHandler);			
            return;
        }

    }
}
